const app = require("http");
const fs = require("fs");
const Events  = require("events");
// 开启一个web服务
app.createServer((req, res) => {
    res.writeHead(200, { 'content-type': 'text/plan' })
    res.end('helloWorld')
}).listen(8888)
// console.log("Server running at http://127.0.0.1:8888/");

// 同步读取
let data = fs.readFileSync('input.txt')
console.log('fs---:', data.toString())
// 一部读取
fs.readFile('./input.txt', (err, data) => {
    if (err) return console.log(err)
    console.log('fs----异步读文件:', data.toString());
})
// loop event
let eventEmitter = new Events.EventEmitter()
eventEmitter.on('sayHello', () => {
    console.log('hello');
})
eventEmitter.emit('sayHello')